package com.cn.algorithm02.class03;

import com.cn.algorithm02.class01.CodeUtil;

/***
 * @author: hels
 * @description: continue 跳过本次循环之后的代码
 * break 跳过当前整个循环体
 **/
public class C06_ContinueAndBreak {
    public static void main(String[] args) {
//        continue2();
//        break1();
        break2();

    }

    static void break1() {
        int k = 0;
        for (int i = 0; i < 5; i++) {
            if (i == 2) {
                System.out.println("k value is " + k + "  ");
                break; // break 会跳过整个循环，进入循环体之后的代码
            }
            k++;
            System.out.println(" i :" + i + " k :" + k);
        }

        System.out.println("循环结束了。。。。");
    }

    static void break2() {
        int k = 0, m = 0;
        do {
            m++;
            if (m == 2) break;

            System.out.println("循环次数：" + m);
        } while (m < 5);

        System.out.println("循环结束了。。。。");
    }

    static void continue1() {
        int k = 0;
        for (int i = 0; i < 5; i++) {
            if (i == 2) {
                System.out.println("k value is " + k + "  ");
                continue; // continue 会跳过当次循环剩下代码，直接跳到下一次循环判断中
            }
            k++;
            System.out.println(" i :" + i + " k :" + k);
        }
    }

    static void continue2() {
        int k = 0, m = 0;
        do {
            m++;
            if (m == 2) continue;

            System.out.println("循环次数：" + m);
        } while (m < 5);
    }


}
